package com.example.wechattakeaway.controller;

import com.example.wechattakeaway.accessctro.RolePermission;
import com.example.wechattakeaway.form.meroptionsform.InsertOptionDetailForm;
import com.example.wechattakeaway.form.meroptionsform.UpdateOptionDetailForm;
import com.example.wechattakeaway.service.OptionDetailService;
import com.example.wechattakeaway.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/OptionDetailController")
@Api(tags = "菜品选项详情管理模块")
public class OptionDetailController {
    @Autowired
    OptionDetailService optionDetailService;

    @ApiOperation(value = "添加菜品选项详情信息",notes = "商家web端")
    @PostMapping("/insertOptionDetail")
    @RolePermission(key = "商家管理员")
    public ResultVO insertOptionDetail(InsertOptionDetailForm insertOptionDetailForm){

        return optionDetailService.insertOptionDetail(insertOptionDetailForm);
    }

    @ApiOperation(value = "编辑菜品选项详情信息",notes = "商家web端")
    @PostMapping("/updateOptionDetail")
    @RolePermission(key = "商家管理员")
    public ResultVO updateOptionDetail(UpdateOptionDetailForm updateOptionDetailForm){

        return optionDetailService.updateOptionDetail(updateOptionDetailForm);
    }

    @ApiOperation(value = "根据菜品选项详情id查询对应菜品选项详情",notes = "小程序端以及商家web端")
    @ApiImplicitParam(name="optionDetailId",value="菜单选项id",example = "1",dataType = "Integer",paramType = "query")
    @GetMapping("/selectDetailById")
    public ResultVO selectDetailById(@RequestParam("optionDetailId") Integer optionDetailId){

        return optionDetailService.selectDetailById(optionDetailId);
    }

    @ApiOperation(value = "根据菜单选项id查询对应菜品选项详情列表（分页）",notes = "商家web端")
    @ApiImplicitParam(name="optionId",value="菜单选项id",example = "1",dataType = "Integer",paramType = "query")
    @GetMapping("/selectDetailByOptionId")
    public ResultVO selectDetailByOptionId(@RequestParam("pageNum") Integer pageNum,@RequestParam("optionId") Integer optionId){

        return optionDetailService.selectDetailByOptionId(pageNum,optionId);
    }

    @ApiOperation(value = "根据菜单选项id查询对应菜品选项详情列表",notes = "小程序端")
    @ApiImplicitParam(name="optionId",value="菜单选项id",example = "1",dataType = "Integer",paramType = "query")
    @GetMapping("/selectByOptionId")
    public ResultVO selectByOptionId(@RequestParam("optionId") Integer optionId){

        return optionDetailService.selectByOptionId(optionId);
    }


    @ApiOperation(value = "根据菜品选项详情id删除菜品选项详情",notes = "商家web端")
    @PostMapping("/deleteOptionDetail")
    @RolePermission(key = "商家管理员")
    public ResultVO deleteOptionDetail(Integer optionDetailId){
        return optionDetailService.deleteOptionDetail(optionDetailId);
    }

}
